// JavaScript Document

function eraseInfo() 
{
  document.getElementById('user-info').value = '';
}

function eraseCheck() 
{
  document.getElementById('check').value = '';
}

function validate() 
{

  var userNameReg = /^[a-zA-Z0-9]([a-zA-Z0-9_.-]){1,20}$/;
  var emailReg = /^[a-zA-Z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-zA-Z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.([a-z]{2,})$/;
  var error = false;

  
  if (!userNameReg.test(document.getElementById('login').value)) {
    document.getElementById('login-info').innerHTML = 'Vyberte si o login délce 2 až 20 znaků, pouze znaky, číslice a podtržítko.';
    document.getElementById('login-info').style.color = 'red';
    error = true;
  }
  else {
    document.getElementById('login-info').innerHTML = 'V pořádku.';
    document.getElementById('login-info').style.color = 'black';
  }
  
  if (document.getElementById('password').value.length < 6) {
    document.getElementById('password-info').innerHTML = 'Heslo musí mít nejméně 6 znaků.';
    document.getElementById('password-info').style.color = 'red';
    error = true;
  }
  else {
    document.getElementById('password-info').innerHTML = 'V pořádku.';
    document.getElementById('password-info').style.color = 'black';
  }  
  
  if (document.getElementById('password').value != document.getElementById('password2').value) {
    document.getElementById('password2-info').innerHTML = 'Heslo se neshodují.';
    document.getElementById('password2-info').style.color = 'red';
    error = true;
  }
  else {
    document.getElementById('password2-info').innerHTML = '';
    document.getElementById('password2-info').style.color = 'black';
  }  
  
  if (!emailReg.test(document.getElementById('email').value) || (document.getElementById('email').value == '') ) {
    document.getElementById('email-info').innerHTML = 'Email nemá správný tvar.';
    document.getElementById('email-info').style.color = 'red';
    error = true;
  }
  else {
    document.getElementById('email-info').innerHTML = 'V pořádku.';
    document.getElementById('email-info').style.color = 'black';
  }  
  
  if (document.getElementById('check').value == '') {
    document.getElementById('check-info').innerHTML = 'Musíte vyplnit ochranu proti spamu.';
    document.getElementById('check-info').style.color = 'red';
    error = true;
  }
  else {
    document.getElementById('check-info').innerHTML = '';
    document.getElementById('check-info').style.color = 'black'; 
  }  
 
 if (!error) {
    return true;
  }
  else {
    return false;
  }    
}